 ///
 /// @file    Queue.cc
 /// @author  lemon(haohb13@gmail.com)
 /// @date    2016-03-08 11:06:03
 ///
 
#include <iostream>

using std::cout;
using std::endl;


template <typename T, int SIZE = 10>
class Queue
{
public:
	Queue()
	: _front(0)
	, _rear(0)
	{
		cout << "Queue()" << endl;
	}

	bool empty();
	bool full();
	T front();
	bool push(const T & obj);
	bool pop();

private:
	//循环数组的使用
	int _front;
	int _rear;
	T _arr[SIZE];
};

template <typename T, int SIZE>
bool Queue<T, SIZE>::empty()
{
	if(_front == _rear)
		return true;
	else
		return false;
}

template <typename T, int SIZE>
bool Queue<T, SIZE>::full()
{
	if(_front == (_rear + 1) % SIZE)
		return true;
	else 
		return false;
}



template <typename T, int SIZE>
T Queue<T, SIZE>::front()
{
	return _arr[_front];
}


template <typename T, int SIZE>
bool Queue<T, SIZE>::push(const T & obj)
{
	if(!full())
	{
		_arr[_rear] = obj;
		_rear = (_rear + 1) % SIZE;
		return true;
	}
	else
		return false;
}

template <typename T, int SIZE>
bool Queue<T, SIZE>::pop()
{
	if(!empty())
	{
		_front = (_front + 1) % SIZE;
		return true;
	}
	else
		return false;
}


int main(void)
{
	Queue<int> que;
	cout << "que 是否为空?" << que.empty() << endl;

	que.push(1);
	cout << "que 是否为空?" << que.empty() << endl;

	for(int idx = 2; idx != 11; ++idx)
	{
		que.push(idx);
	}
	cout << "que 是否已满?" << que.full() << endl;

	while(!que.empty())
	{
		cout << que.front() << " ";
		que.pop();
	}

	cout << endl;
}

